package com.nextbus.ui;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class MyOverlay extends ItemizedOverlay<OverlayItem>{
		//创建一个List对象，用于持有该图层当中所有的标记对象
		private ArrayList<OverlayItem> overlayItems = new ArrayList<OverlayItem>();
		private Context context;
			
		//这个构造函数的super（）函数还是不能乱写的
		public MyOverlay(Drawable defaultMarker,Context context) {
			super(boundCenterBottom(defaultMarker));
			this.context = context;
		}
		public MyOverlay(Drawable defaultMarker) {
			super(boundCenterBottom(defaultMarker));
		}
		
		
		Location location;
		public void setLocation(Location location){
			this.location=location;
		}
		
		//用于将生成好的OverlayItem对象添加到List当中
		public void addOverlay(OverlayItem overlayItem){
			overlayItems.add(overlayItem);
			//新的数据被添加以后我们需要调用这个populate来完成一些操作
			populate();
		}
		
		
		//用于创建一个OverLayItem对象
		@Override
		protected OverlayItem createItem(int i) {
			// TODO Auto-generated method stub
			return overlayItems.get(i);
		}
		
		
		//返回当前的OverLay当中所包含的OverlayItem对象
		@Override
		public int size() {
			// TODO Auto-generated method stub
			return overlayItems.size();
		}
		
		/*
		 * 当用户点击标记时，所调用的函数,显示一个提示信息
		 * @see com.google.android.maps.ItemizedOverlay#onTap(int)
		 */
		@Override
		protected boolean onTap(int index) {
			OverlayItem item = overlayItems.get(index);
			AlertDialog.Builder builder = new AlertDialog.Builder(context);
			
			builder.setTitle(item.getTitle());
			builder.setMessage(item.getSnippet());
			Dialog dialog = builder.create();
			dialog.show();
			return true;
		}
}
